<!DOCTYPE html>
<html>
<script src="../../../../resources/js-test.js"></script>
<style type="text/css">
#frame {
    position: absolute;
    top: 300px;
    left: 400px;
    height: 3000px;
}
</style>
<body>
<iframe src='resources/gesture-tap-active-state-iframe-inner.html' id='frame'>
</iframe>

<p id="description"></p>
<p>See https://bugs.webkit.org/show_bug.cgi?id=96060 for details</p>

<div id="console"></div>

<script src="../resources/touch-hover-active-tests.js"></script>
<script>
var box;

description("Tests that tap gesture events set and clear the active state of elements, even when inside an iframe and the document is scrolled.");

function runTests()
{
    if (!window.eventSender) {
        debug('This test requires DRT.');
        return;
    }

    if (!eventSender.gestureShowPress) {
        debug('GestureShowPress is not supported by this platform');
        return;
    }

    box = document.getElementById("frame").contentDocument.getElementById('box');

    // Scroll so the box is at the top
    window.scrollTo(0, 400);

    debug("Verify active isn't initially set");
    shouldBeDefault("getHoverActiveState(box)");

    debug("Verify showPress, tap sets and clears active");
    eventSender.gestureTapDown(450, 50);
    eventSender.gestureShowPress(450, 50);
    shouldBeHoveredAndActive("getHoverActiveState(box)");
    eventSender.gestureTap(450, 50);
    // FIXME: Enable after implementing mocked timers (http://crbug.com/319529)
    // shouldBeTrue("isBoxActive()");
    waitUntilActiveCleared();
}

function waitUntilActiveCleared()
{
    if(getHoverActiveState(box) == "hoveredAndActive") {
        return setTimeout(waitUntilActiveCleared, 10);
    }

    shouldBeOnlyHovered("getHoverActiveState(box)");
    finishJSTest();
}

if (window.testRunner) {
    window.jsTestIsAsync = true;
    testRunner.waitUntilDone();
}

window.onload = runTests;
</script>
</body>
</html>
